/**   
 * @Title: SportteryFootballAgainstInfoCommunicater.java 
 * @Package com.esun.rabbit2.communicaters.sportteryfootball 
 * @Description: (通讯接口,业务代码10038) 
 * @author: City Jiangsy@500wan.com   
 * @date: 2011-8-3 上午10:05:02  
 * Copyright: (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.communicaters.sportteryfootball;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.client.ClientProtocolException;
import org.xml.sax.SAXException;

import com.esun.config.BussinessCode;
import com.esun.config.Config;
import com.esun.config.Key;
import com.esun.model.sportteryfootball.SportteryFootballAgainstInfo;
import com.esun.network.ServerCommunicater;

/**
 * @ClassName: SportteryFootballAgainstInfoCommunicater
 * @Description: (获取竞彩足球对阵信息)
 * @author: City Jiangsy@500wan.com
 * @date: 2011-8-3 上午10:05:02
 * 
 */
public class SportteryFootballAgainstInfoCommunicater extends ServerCommunicater {
	private String msgServer; // 服务器信息
	private boolean isSucceed = false;

	private int type;

	public String getMsgServer() {
		return msgServer;
	}

	public void setMsgServer(String msgServer) {
		this.msgServer = msgServer;
	}

	public boolean isGetInfoSucceed(int type, boolean isRangqiu, boolean isUnRangqiu, boolean isJiezhi, String strTeamList, int peilvArea) throws ClientProtocolException, IOException,
			ParserConfigurationException, SAXException {
		this.type = type;

		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		list.add(mapItem(BussinessCode.PASER_MID, BussinessCode.MID_SPORTTERFOOTBALL_AGAINSTINFO));
		list.add(mapItem(Key.KEY_TEAMLIST, strTeamList));
		list.add(mapItem(Key.KEY_TYPE, Integer.toString(type)));
		if (isRangqiu) {
			list.add(mapItem(Key.KEY_RANGQIU, Config.NUM1));
		} else {
			list.add(mapItem(Key.KEY_RANGQIU, Config.NUM0));
		}
		if (isUnRangqiu) {
			list.add(mapItem(Key.KEY_UNRANGQIU, Config.NUM1));
		} else {
			list.add(mapItem(Key.KEY_UNRANGQIU, Config.NUM0));
		}
		if (isJiezhi) {
			list.add(mapItem(Key.KEY_JIEZHI, Config.NUM1));
		} else {
			list.add(mapItem(Key.KEY_JIEZHI, Config.NUM0));
		}
		list.add(mapItem(Key.KEY_PEILVAREA, Integer.toString(peilvArea)));
		// 写入服务器返回信息
		super.getServerResponse(list, true);
		setMsgServer(super.getErrorMSG());
		if (super.getState() == 100) {
			isSucceed = true;
		} else {
			isSucceed = false;
		}
		return isSucceed;
	}


	public ArrayList<SportteryFootballAgainstInfo> getAgainstInfoList() {

		ArrayList<SportteryFootballAgainstInfo> listSportteryFootballAgainstInfos = new ArrayList<SportteryFootballAgainstInfo>();

		for (int i = 0; i < super.getListResult().size(); i++) {
			SportteryFootballAgainstInfo sportteryFootballAgainstInfo = new SportteryFootballAgainstInfo();
			sportteryFootballAgainstInfo.setMatchNum(super.getListResult().get(i).get(Key.KEY_MATCHNUM));
			sportteryFootballAgainstInfo.setMatchNumDate(super.getListResult().get(i).get(Key.KEY_MATCHNUMDATE));
			sportteryFootballAgainstInfo.setDayOfWeek(super.getListResult().get(i).get(Key.KEY_DAYOFWEEK));
			sportteryFootballAgainstInfo.setId(super.getListResult().get(i).get(Key.KEY_ID));
			sportteryFootballAgainstInfo.setSimpleLeague(super.getListResult().get(i).get(Key.KEY_SIMPLELEAGUE));
			sportteryFootballAgainstInfo.setHomeSxName(super.getListResult().get(i).get(Key.KEY_HOMESXNAME));
			sportteryFootballAgainstInfo.setAwaySxName(super.getListResult().get(i).get(Key.KEY_AWAYSXNAME));
			sportteryFootballAgainstInfo.setPtggEndTime(super.getListResult().get(i).get(Key.KEY_PTGGENDTIME));
			sportteryFootballAgainstInfo.setxId(super.getListResult().get(i).get(Key.KEY_XID));
			sportteryFootballAgainstInfo.setProcessName(super.getListResult().get(i).get(Key.KEY_PROCESSNAME));

			if (type == 1 || type == 2) {
				sportteryFootballAgainstInfo.setWin(super.getListResult().get(i).get(Key.KEY_WIN));
				sportteryFootballAgainstInfo.setLost(super.getListResult().get(i).get(Key.KEY_LOST));
				sportteryFootballAgainstInfo.setDraw(super.getListResult().get(i).get(Key.KEY_DRAW));
				sportteryFootballAgainstInfo.setRangqiu(super.getListResult().get(i).get(Key.KEY_RANGQIU));

			} else if (type == 3 || type == 4) {
				sportteryFootballAgainstInfo.setsZero(super.getListResult().get(i).get(Key.KEY_S0));
				sportteryFootballAgainstInfo.setsOne(super.getListResult().get(i).get(Key.KEY_S1));
				sportteryFootballAgainstInfo.setsTwo(super.getListResult().get(i).get(Key.KEY_S2));
				sportteryFootballAgainstInfo.setsThree(super.getListResult().get(i).get(Key.KEY_S3));
				sportteryFootballAgainstInfo.setsFour(super.getListResult().get(i).get(Key.KEY_S4));
				sportteryFootballAgainstInfo.setsFive(super.getListResult().get(i).get(Key.KEY_S5));
				sportteryFootballAgainstInfo.setsSix(super.getListResult().get(i).get(Key.KEY_S6));
				sportteryFootballAgainstInfo.setsSeven(super.getListResult().get(i).get(Key.KEY_S7));

			} else if (type == 5 || type == 6) {
				updataScoreInfo(sportteryFootballAgainstInfo, i);

			} else if (type == 7 || type == 8) {
				sportteryFootballAgainstInfo.setAa(super.getListResult().get(i).get(Key.KEY_AA));
				sportteryFootballAgainstInfo.setAb(super.getListResult().get(i).get(Key.KEY_AB));
				sportteryFootballAgainstInfo.setAc(super.getListResult().get(i).get(Key.KEY_AC));
				sportteryFootballAgainstInfo.setBa(super.getListResult().get(i).get(Key.KEY_BA));
				sportteryFootballAgainstInfo.setBb(super.getListResult().get(i).get(Key.KEY_BB));
				sportteryFootballAgainstInfo.setBc(super.getListResult().get(i).get(Key.KEY_BC));
				sportteryFootballAgainstInfo.setCa(super.getListResult().get(i).get(Key.KEY_CA));
				sportteryFootballAgainstInfo.setCb(super.getListResult().get(i).get(Key.KEY_CB));
				sportteryFootballAgainstInfo.setCc(super.getListResult().get(i).get(Key.KEY_CC));

			} else {

			}
			listSportteryFootballAgainstInfos.add(sportteryFootballAgainstInfo);
		}
		return listSportteryFootballAgainstInfos;
	}

	/**
	 * @Title: updataScoreInfo
	 * @Description: 导入type为比分时的数据
	 * @param: @param sportteryFootballAgainstInfo
	 * @param: @param i 设定文件
	 * @return: void 返回类型
	 * @throws
	 */
	private void updataScoreInfo(SportteryFootballAgainstInfo sportteryFootballAgainstInfo, int i) {
		sportteryFootballAgainstInfo.setaOneZero(super.getListResult().get(i).get(Key.KEY_A10));
		sportteryFootballAgainstInfo.setaTwoZero(super.getListResult().get(i).get(Key.KEY_A20));
		sportteryFootballAgainstInfo.setaTwoOne(super.getListResult().get(i).get(Key.KEY_A21));
		sportteryFootballAgainstInfo.setaThreeZero(super.getListResult().get(i).get(Key.KEY_A30));
		sportteryFootballAgainstInfo.setaThreeOne(super.getListResult().get(i).get(Key.KEY_A31));
		sportteryFootballAgainstInfo.setaThreeTwo(super.getListResult().get(i).get(Key.KEY_A32));
		sportteryFootballAgainstInfo.setaFourZero(super.getListResult().get(i).get(Key.KEY_A40));
		sportteryFootballAgainstInfo.setaFourOne(super.getListResult().get(i).get(Key.KEY_A41));
		sportteryFootballAgainstInfo.setaFourTwo(super.getListResult().get(i).get(Key.KEY_A42));
		sportteryFootballAgainstInfo.setaFiveZero(super.getListResult().get(i).get(Key.KEY_A50));
		sportteryFootballAgainstInfo.setaFiveOne(super.getListResult().get(i).get(Key.KEY_A51));
		sportteryFootballAgainstInfo.setaFiveTwo(super.getListResult().get(i).get(Key.KEY_A52));
		sportteryFootballAgainstInfo.setaOther(super.getListResult().get(i).get(Key.KEY_AOTHER));

		sportteryFootballAgainstInfo.setcZeroZero(super.getListResult().get(i).get(Key.KEY_C00));
		sportteryFootballAgainstInfo.setcOneOne(super.getListResult().get(i).get(Key.KEY_C11));
		sportteryFootballAgainstInfo.setcTwoTwo(super.getListResult().get(i).get(Key.KEY_C22));
		sportteryFootballAgainstInfo.setcThreeThree(super.getListResult().get(i).get(Key.KEY_C33));
		sportteryFootballAgainstInfo.setcOther(super.getListResult().get(i).get(Key.KEY_COTHER));

		sportteryFootballAgainstInfo.setbOneZero(super.getListResult().get(i).get(Key.KEY_B10));
		sportteryFootballAgainstInfo.setbTwoZero(super.getListResult().get(i).get(Key.KEY_B20));
		sportteryFootballAgainstInfo.setbTwoOne(super.getListResult().get(i).get(Key.KEY_B21));
		sportteryFootballAgainstInfo.setbThreeZero(super.getListResult().get(i).get(Key.KEY_B30));
		sportteryFootballAgainstInfo.setbThreeOne(super.getListResult().get(i).get(Key.KEY_B31));
		sportteryFootballAgainstInfo.setbThreeTwo(super.getListResult().get(i).get(Key.KEY_B32));
		sportteryFootballAgainstInfo.setbFourZero(super.getListResult().get(i).get(Key.KEY_B40));
		sportteryFootballAgainstInfo.setbFourOne(super.getListResult().get(i).get(Key.KEY_B41));
		sportteryFootballAgainstInfo.setbFourTwo(super.getListResult().get(i).get(Key.KEY_B42));
		sportteryFootballAgainstInfo.setbFiveZero(super.getListResult().get(i).get(Key.KEY_B50));
		sportteryFootballAgainstInfo.setbFiveOne(super.getListResult().get(i).get(Key.KEY_B51));
		sportteryFootballAgainstInfo.setbFiveTwo(super.getListResult().get(i).get(Key.KEY_B52));
		sportteryFootballAgainstInfo.setbOther(super.getListResult().get(i).get(Key.KEY_BOTHER));

	}

	/**
	 * @Title: mapItem
	 * @Description: (工具类,用于构建AraayList单条内容)
	 * @param @param name 参数名
	 * @param @param value 参数值
	 * @param @return map
	 * @return HashMap<String,String> 返回类型
	 * @throws
	 */
	private HashMap<String, String> mapItem(String name, String value) {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put(name, value);
		return map;
	}

}
